package com.woniuxy.warehouse.controller;

import com.woniuxy.commons.entity.warehouse.dto.StockInDetailsDto;
import com.woniuxy.commons.entity.warehouse.vo.warehouse.TypeAndCodeVo;
import com.woniuxy.commons.result.Result;
import com.woniuxy.warehouse.service.StockInDetailsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Author:SHEAndme
 * @Todo:TODO  入库详情表
 * @DateTime:2022/4/22 9:52
 * @Component:霍格沃兹魔法学院
 **/
@RestController
@RequestMapping("/warehouse/stockInDetails")
public class StockInDetailsController {
    @Resource
    private StockInDetailsService stockInDetailsService;

    //尝试使用redis
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @ApiOperation(value = "入库的详情页---产品信息")
    @PostMapping("/findAllStockInDetails/{pageNum}/{pageSize}")
    public Result findAllStockInDetails(@PathVariable("pageNum") Integer currentPage,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @RequestBody StockInDetailsDto stockInDetailsDto){

return  stockInDetailsService.findAllStockInDetails(currentPage,pageSize,stockInDetailsDto);
    }
/**
 * @param currentPage:
 * @param pageSize:
 * @param stockInDetailsDto:
 * @return Result
 * @description TODO  redis
 */
    @ApiOperation(value = "入库的详情页---产品信息")
    @PostMapping("/findAllStockInDetailsByRedis/{pageNum}/{pageSize}")
    public Result findAllStockInDetailsByRedis(@PathVariable("pageNum") Integer currentPage,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @RequestBody StockInDetailsDto stockInDetailsDto){

         Result findDetails = stockInDetailsService.findAllStockInDetails(currentPage,pageSize,stockInDetailsDto);
         String key = "findAllStockInDetails::"+ currentPage
                 + ':' + pageSize + ':'
                 +stockInDetailsDto.getIoOrderNo();

        if (stockInDetailsService.isExpire(key)==-1) {
            redisTemplate.expire(key, 1, TimeUnit.MINUTES);
        }
        return findDetails;

    }

//Inventory management

    @ApiOperation(value = "库存管理")
    @PostMapping("/findAllInventory/{pageNum}/{pageSize}")
    public Result findAllInventory(@PathVariable("pageNum") Integer currentPage,
                                   @PathVariable("pageSize") Integer pageSize,
                                   @RequestBody TypeAndCodeVo typeAndCodeVo){

        return  stockInDetailsService.findAllInventory(currentPage,pageSize,typeAndCodeVo);
    }




}
